package com.money.common.valid;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.MessageSource;
import org.w3c.dom.ranges.Range;

import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;
import java.util.HashSet;
import java.util.Set;

public class RangeValidator implements ConstraintValidator<RangeValues,Integer> {

    private final Set<Integer> set = new HashSet<>();

    @Override
    public void initialize(RangeValues constraintAnnotation) {
        for (int value : constraintAnnotation.values()) {
            set.add(value);
        }
//        ConstraintValidator.super.initialize(constraintAnnotation);

    }

    @Override
    public boolean isValid(Integer value, ConstraintValidatorContext context) {
        return set.contains(value);
    }
}
